package com.cust.cow.service.impl;

import com.baomidou.mybatisplus.core.conditions.update.UpdateWrapper;
import com.cust.cow.common.Result;
import com.cust.cow.mapper.MatingLogMapper;
import com.cust.cow.pojo.matingLog;
import com.cust.cow.service.MatingLog;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class MatingLogImpl implements MatingLog {
    @Autowired
    MatingLogMapper matingLogMapper;
    @Override
    public List<matingLog> findMatingLogAll() {
        return matingLogMapper.findMatingLogAll();
    }

    @Override
    public Result insertMatingLog(matingLog matingLog) {
        matingLogMapper.insertMatingLog(matingLog);
        return new Result(200, "插入成功");
    }

    @Override
    public Result deleteMatingLog(Integer cattleId) {
        matingLogMapper.deleteMatingLog(cattleId);
        return new Result(200, "删除成功");
    }

    @Override
    public Result updateMatingLog(matingLog matingLog) {
        UpdateWrapper<matingLog> updateWrapper = new UpdateWrapper<>();
        updateWrapper.eq("cattle_id", matingLog.getCattleId())
                .set("mating_date", matingLog.getMatingDate())
                .set("state", matingLog.getState());

        int result = matingLogMapper.update(matingLog,updateWrapper);

        if (result <= 0) {
            return new Result(100, "更新失败");
        }
        return new Result(200, "更新成功");
    }
}
